﻿namespace eBenefits.App.Helpers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web.Security;

    /// <summary>
    /// Data helper
    /// </summary>
    public sealed class DataHelper
    {
        public static string GetConfigValue(string configValue, string defaultValue)
        {
            if (String.IsNullOrEmpty(configValue))
                return defaultValue;

            return configValue;
        }

        public static string GetString(string configValue, string defaultValue)
        {
            if (configValue == null)
                return defaultValue;

            return configValue;
        }

        public static int GetInt(string testValue, int defaultValue)
        {
            int parsedValue;

            if (int.TryParse(testValue, out parsedValue))
                return parsedValue;

            return defaultValue;
        }

        public static bool GetBool(string testValue, bool defaultValue)
        {
            bool parsedValue;

            if (bool.TryParse(testValue, out parsedValue))
                return parsedValue;

            return defaultValue;
        }

        public static MembershipPasswordFormat GetPasswordFormat(string testValue, MembershipPasswordFormat defaultValue)
        {
            MembershipPasswordFormat parsedValue;

            if (Enum.TryParse<MembershipPasswordFormat>(testValue, out parsedValue))
            {
                return parsedValue;
            }

            return defaultValue;
        }
    }
}
